package com.cys.dm.controller;

import com.cys.dm.entity.base.DmArea;
import com.cys.dm.entity.item.DmItemType;
import com.cys.dm.rest.service.DmAreaService;
import com.cys.dm.vo.CommonResponse;
import com.cys.dm.vo.VoUtil;
import com.cys.dm.vo.dmes.DmItemRowsEs;
import com.cys.dm.vo.dmitem.DmItemRowsPageResponse;
import com.cys.dm.vo.dmitem.DmItemTypeResponse;
import com.cys.dm.vo.itemlist.QueryItemList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class DmAreaController {
    @Autowired
    private DmAreaService dmAreaService;

    /**
     * 列表页 1. 查询市区API接口
     * @return
     */
    @PostMapping("/querycity")
    public CommonResponse<List<DmArea>> querycity(){
        List<DmArea> areas = dmAreaService.dmAreaList();
        return VoUtil.returnSuccess("所有城市查询成功",areas);
    }

    /**
     * 列表页 2. 查询分类接口
     * @return
     */
    @PostMapping(path = "/sortgoods")
    public CommonResponse<List<DmItemTypeResponse>> sortgoods(@RequestBody Map<String,Long> map){
        List<DmItemTypeResponse> dmItemTypes = dmAreaService.queryItemType(map);
        return VoUtil.returnSuccess("一级标题查询成功",dmItemTypes);
    }

    /**
     * 3. 根据城市、一级分类、二级分类查询商品信息
     * @param
     * @return
     */
    @PostMapping(path = "/querygoodsinfos")
    public CommonResponse<DmItemRowsPageResponse<DmItemRowsEs>> querygoodsinfos(@RequestBody Map<String,String> params){
        DmItemRowsPageResponse<DmItemRowsEs> dmItemRowsPageResponse = dmAreaService.querygoodsinfos(params);
        //添加图片
        return VoUtil.returnSuccess("商品查询成功,",dmItemRowsPageResponse);
    }

    @PostMapping(path = "/guesslike")
    public CommonResponse<List<QueryItemList>> guesslike(@RequestBody Map<String,Long> params){
        List<QueryItemList> queryItemLists = dmAreaService.queryItemList(params.get("itemTypeId"));
        return VoUtil.returnSuccess("猜你喜欢",queryItemLists);
    }
}
